/*
 * loadCatalog.java
 *
 * Created on March 26, 2007, 7:11 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.actions;

import javax.servlet.http.*;
import edu.byu.isys413.group1E.data.*;
import edu.byu.isys413.group1E.handlers.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/**This action loads up a list of items that can be purchased over the internet.  It also clears the transaction
 *
 * @author Kendall Frazier
 */
public class loadCatalog implements edu.byu.isys413.web.Action {
    
    /** Creates a new instance of loadCatalog */
    public loadCatalog() {
    }
    
    /** 
     *Processes this method loads in the catalog of items that the user can purchase from.  It creates an ArrayList of ConceptualBO's
     *which the catalog.jsp can display to the user.  Also, at this point we know the user is going to make a "sale" transaction, so
     *a new transaction object is created and saved over the old one.  In the GUI, a warning displays before this action is performed.
     *
     *@param HttpServletRequest
     *@param HttpServletResponse
     *
     *@return String the name of the jsp to call
     */
    public String process(HttpServletRequest request, HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();
        SaleHandler sHandler = SaleHandler.getInstance();
        TransactionDAO TXDAO = TransactionDAO.getInstance();
        UpdateController updateController = UpdateController.getInstance();
        
        ArrayList<ConceptualBO> catalog = sHandler.getCatalog();
        
        //BEING CLEAR
        TransactionBO TXBO = TXDAO.create();
        CustomerBO customer = (CustomerBO)session.getAttribute("customer");
        TXBO.setCustomerID(customer.getCustID());        
        TXBO.setStoreID("0000011106a3cc370000007f000002");
        TXBO.setEmployeeID("0000011106a3cc390000007f000002");
        //set the date for the transaction
        Calendar cal = Calendar.getInstance();
        Date today = cal.getTime();
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
        String todayDate = fmt.format(today);
        TXBO.setTransDate(todayDate);
        session.setAttribute("TX", TXBO);
        //End CLEAR
        
        request.setAttribute("catalog", catalog);
                
//        session.setAttribute("catalog", catalog);        
        return "catalog.jsp";
    }//process
    
    
}//loadCatalog class
